home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- /*
- * AZN_TStr255.h
- *
- * Class declaration for 'TStr55' class, a utility
- * class to replace Str255 and allow for easier
- * string manipulation
- * Inheritance: BASE CLASS
- *
- * © Andrew Nemeth Warrimoo Australia 1995
- * aznemeng@zeta.org.au
- *
- * File created: 5 Jun 95
- * Modified: 5, 28 Jun;
- * 2, 23 Oct 95.
- */
-
-
- #include <stddef.h> // defn of 'size_t'
-
-
- // CLASS dec
- //
- class TStr255
- {
- public:
- TStr255();
- ~TStr255(){};
- // typecast to 'StringPtr'
- operator StringPtr ();
- // construct with Str255
- TStr255( ConstStr255Param );
- // assign/concat Str255
- TStr255 & operator = ( ConstStr255Param );
- TStr255 & operator += ( ConstStr255Param );
- // assign/concat C strings
- TStr255 & operator = ( const char * );
- TStr255 & operator += ( const char * );
- // assign/concat ONTO C strs
- void copy2C ( char * );
- void cat2C ( char * );
- // compare with Str255
- Boolean operator == ( ConstStr255Param );
- // array indexing
- unsigned char operator [] ( const short );
- // grab class Str255 size byte
- unsigned char operator * ();
- // set max length of Str255
- void setMaxLength ( const short );
-
- private:
- Str255 f_str255Item;
- // never create heap-based objects!
- void * operator new ( size_t );
-
- short minNum( short, short );
- long myStrlen( register char * );
- };
-
-
-
- // INLINES
- //
- inline TStr255::TStr255()
- //
- // Inline constructor
- //
- {
- f_str255Item[0] = 0;
- }
-
-
-
- inline TStr255::operator StringPtr ()
- //
- // Overloaded typecast operator to 'StringPtr'.
- // This allows object to be used as a replacement
- // Str255 in functions which require this parameter!
- //
- {
- return( (StringPtr)&f_str255Item[0] );
- }
-
-
-
- inline TStr255::TStr255( ConstStr255Param str255S )
- //
- // Copy Construct with Str255
- //
- {
- ::BlockMoveData( StringPtr(str255S), f_str255Item, str255S[0] + 1 );
- }
-
-
-
- inline short TStr255::minNum( short x, short y )
- //
- // Return smallest number
- //
- {
- return( ( x < y ) ? x : y );
- }
-
-
-
- inline Boolean TStr255::operator==( ConstStr255Param str255S )
- //
- // Compare object with string
- //
- {
- return( ::EqualString( str255S, f_str255Item, TRUE, TRUE ) );
- }
-
-
- inline unsigned char TStr255::operator[]( const short shNdx )
- //
- // Array indexing
- //
- {
- return( f_str255Item[shNdx] );
- }
-
-
- inline unsigned char TStr255::operator * ()
- //
- // Grab size byte of Str255
- //
- {
- return( f_str255Item[0] );
- }
-
-
- inline void TStr255::setMaxLength( const short shNdx )
- //
- // Set max length of string
- //
- {
- if ( shNdx >= 0 && shNdx <= 255 )
- f_str255Item[0] = shNdx;
- }
-